<div class="dtree">
	<?php
		$menu_types = getMenuTypes();
		if($menu_types)
		{
			echo ' <script type="text/javascript"> ';
			echo ' d = new dTree(\'d\'); ';
			echo ' d.add(0,-1,\'Component MenuTypes\',\'?con='.$_REQUEST['con'].'\',\'\',\'\',\'img/globe.gif\',\'img/globe.gif\'); ';
			echo ' d.add(1,0,\'All MenuTypes ('.count($menu_types).')\',\'?con='.$_REQUEST['con'].'\', \'\',\'\',\'img/folder.gif\'); ';
			
			echo ' d.add(2,0,\'Horisontal (CSS)\',\'?con='.$_REQUEST['con'].'&amp;type=0\', \'\',\'\',\'img/folder.gif\'); ';
			echo ' d.add(3,0,\'Horisontal Dropdown(CSS-JS)\',\'?con='.$_REQUEST['con'].'&amp;type=2\', \'\',\'\',\'img/folder.gif\'); ';
			echo ' d.add(4,0,\'Horisontal Double (CSS)\',\'?con='.$_REQUEST['con'].'&amp;type=4\', \'\',\'\',\'img/folder.gif\'); ';
			echo ' d.add(5,0,\'Vertical (CSS)\',\'?con='.$_REQUEST['con'].'&amp;type=1\', \'\',\'\',\'img/folder.gif\'); ';
			echo ' d.add(6,0,\'Dropdown (CSS-JS)\',\'?con='.$_REQUEST['con'].'&amp;type=3\', \'\',\'\',\'img/folder.gif\'); ';

			$j=7;
			foreach($menu_types as $menu_type)
			{
				echo ' d.add('.$j.',1,\''.$menu_type['name'].'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level=0&amp;position=1\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
				
				if(($menu_type['id'] == $_REQUEST['item']))
				{ $openTo = $j; }
				
				$parent = $j;
				
				for($i=0; $i <= getMenuTopLevel($menu_type['id']); $i++)
				{
					if(hasMenuPosition($menu_type['id'], $i, 0))
					{
						$j++;
						if(($menu_type['id'] == $_REQUEST['item']) && ($_REQUEST['level'] == $i) && ($_REQUEST['position'] == 0))
						{ $openTo = $j; }
						
						echo ' d.add('.$j.','.$parent.',\''.'Level '.$i.' First'.'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level='.$i.'&amp;position=0\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
					}
					
					if($i > 0)
					{
						$j++;
						if(($menu_type['id'] == $_REQUEST['item']) && ($_REQUEST['level'] == $i) && ($_REQUEST['position'] == 1))
						{ $openTo = $j; }
						echo ' d.add('.$j.','.$parent.',\''.'Level '.$i.''.'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level='.$i.'&amp;position=1\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
					}
					
					if(hasMenuPosition($menu_type['id'], $i, 2))
					{
						$j++;
						if(($menu_type['id'] == $_REQUEST['item']) && ($_REQUEST['level'] == $i) && ($_REQUEST['position'] == 2))
						{ $openTo = $j; }
						echo ' d.add('.$j.','.$parent.',\''.'Level '.$i.' Last'.'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level='.$i.'&amp;position=2\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
					}
				}
				$j++;
			}
			
			foreach($menu_types as $menu_type)
			{
				$type_parent = 1;
				switch ($menu_type['type'])
				{
					case 0:
						$type_parent = 2;
						break; 
					case 1:
						$type_parent = 5;
						break; 
					case 2:
						$type_parent = 3;
						break; 
					case 3:
						$type_parent = 6;
						break; 
					case 4:
						$type_parent = 4;
						break; 
				} 
				
				echo ' d.add('.$j.','.$type_parent.',\''.$menu_type['name'].'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level=0&amp;position=1&amp;type='.$menu_type['type'].'\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
				
				if(($menu_type['type'] == $_REQUEST['type']) && ($menu_type['id'] == $_REQUEST['item']))
				{ $openTo = $j; }
				
				$parent = $j;
				
				for($i=0; $i <= getMenuTopLevel($menu_type['id']); $i++)
				{
					if(hasMenuPosition($menu_type['id'], $i, 0))
					{
						$j++;
						if(($menu_type['id'] == $_REQUEST['item']) && ($_REQUEST['level'] == $i) && ($_REQUEST['position'] == 0))
						{ $openTo = $j; }
						
						echo ' d.add('.$j.','.$parent.',\''.'Level '.$i.' First'.'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level='.$i.'&amp;position=0&amp;type='.$menu_type['type'].'\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
					}
					
					if($i > 0)
					{
						$j++;
						if(($menu_type['id'] == $_REQUEST['item']) && ($_REQUEST['level'] == $i) && ($_REQUEST['position'] == 1))
						{ $openTo = $j; }
						echo ' d.add('.$j.','.$parent.',\''.'Level '.$i.''.'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level='.$i.'&amp;position=1&amp;type='.$menu_type['type'].'\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
					}
					
					if(hasMenuPosition($menu_type['id'], $i, 2))
					{
						$j++;
						if(($menu_type['id'] == $_REQUEST['item']) && ($_REQUEST['level'] == $i) && ($_REQUEST['position'] == 2))
						{ $openTo = $j; }
						echo ' d.add('.$j.','.$parent.',\''.'Level '.$i.' Last'.'\',\'?con='.$_REQUEST['con'].'&amp;item='.$menu_type['id'].'&amp;level='.$i.'&amp;position=2&amp;type='.$menu_type['type'].'\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
					}
				}
				$j++;
			}
			
			foreach($hfbcats as $hfbcat)
			{
				$catItems = getHFBCatItems($hfbcat['id'], 7);
				echo ' d.add('.$j.',0,\''.$hfbcat['title'].' ('.count($catItems).') '.'\',\'?con='.$_REQUEST['con'].'&amp;cat='.$hfbcat['id'].'\',\'\',\'\',\'img/folder.gif\',\'img/folder.gif\'); ';
				if(($_REQUEST['cat'] > 0) && ($hfbcat['id'] == $_REQUEST['cat']))
				{ $openTo = ($j); }
				$parent = $j;
				$j++;
				
				if($catItems)
				{
					foreach($catItems as $catItem)
					{
						foreach($menu_types as $menu_type)
						{
							if($menu_type['id'] == $catItem['item_id'])
							{
								echo ' d.add('.$j.','.$parent.',\''.$menu_type['name'].'\',\'?con='.$_REQUEST['con'].'&amp;cat='.$hfbcat['id'].'&amp;item='.$menu_type['id'].'\',\'\',\'\',\'img/imgfolder.gif\',\'img/imgfolder.gif\'); ';
								if(($_REQUEST['cat'] > 0) && ($hfbcat['id'] == $_REQUEST['cat']) && ($menu_type['id'] == $_REQUEST['item']))
								{ 
									$openTo = $j; 
								}
								$j++;
							}
						}
					}
				}
			}
			echo ' document.write(d); ';
			if($openTo > 0)
			{ echo ' d.openTo('.$openTo.', true); '; }
			echo ' </script> ';
		}
	?>
</div>